﻿   @model Models.CMS_Keyword
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta name="description" content="Crush it Able The most popular Admin Dashboard template and ui kit">
    <meta name="author" content="PuffinTheme the theme designer">

    <link rel="icon" href="~/Crushit/light/favicon.ico" type="image/x-icon" />

    <title>:: Crush it :: Table Normal</title>

    <!-- Bootstrap Core and vandor -->
    @*<link rel="stylesheet" href="http://cdn.bootstrapmb.com/bootstrap/4.3.1/css/bootstrap.min.css" />*@

    <!-- Core css -->
    <link rel="stylesheet" href="/Crushit/assets/css/main.css" />
    <link rel="stylesheet" href="/Crushit/assets/css/theme4.css" id="stylesheet" />
    <style>

        button {
            background-color: #CCE8EB; /* Green */
            border: none;
            color: #666;
            /*padding: 15px 32px;*/
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
            border: 1px solid #cad9ea;
        }

        #table {
            margin-left: 22%;
            font-size: 14px;
            width: 79%;
            border-collapse: collapse;
            text-align: center;
        }

            #table td, table th {
                border: 1px solid #cad9ea;
                color: #666;
                height: 30px;
            }

        table thead th {
            background-color: #CCE8EB;
            width: 100px;
        }

        table tr:nth-child(odd) {
            background: #fff;
        }

        table tr:nth-child(even) {
            background: #F5FAFA;
        }
    </style>
</head>

<body>
    @using (Html.BeginForm(FormMethod.Post))
    {
    <table id="table">
        <tr style="display:none">
            <td>
                @Html.DisplayNameFor(x => x.kid)
            </td>
            <td>
                <input id="kid" name="kid" />
            </td>
        </tr>
        <tr>
            <td>
                @Html.DisplayNameFor(x => x.keyword)
            </td>
            <td>
                <input id="keyword" name="keyword" />
            </td>
        </tr>
        <tr>
            <td>
                @Html.DisplayNameFor(x => x.stimes)
            </td>
            <td>
                <input id="stimes" name="stimes" />
            </td>
        </tr>
        <tr>
            <td>
                @Html.DisplayNameFor(x => x.ltimes)
            </td>
            <td>
                <input id="ltimes" name="ltimes" type="datetime"/>
            </td>
        </tr>
        <tr>
            <td>
                @Html.DisplayNameFor(x => x.show)
            </td>
            <td>
                <select id="show" name="show">
                    <option value="1">是</option>
                    <option value="0">否</option>
                </select>
            </td>
        </tr>
        <tr>
            <td colspan="2"><button onclick="update()">修改</button><button onclick="fan()">返回</button></td>
        </tr>
    </table>

    }
    <script src="/Crushit/assets/bundles/lib.vendor.bundle.js"></script>
    <script src="/Crushit/assets/js/core.js"></script>
    <script>
        var id = window.location.search.split('=')[1];
        window.onload = function () {

            /*alert(cms.kid);*/
            $.ajax({
                type: "post",
                url: "@Url.Action("UpdateCMS_Keywords")",
                data: JSON.stringify({ kid: id }),
                datatype: "json",
                contentType: "application/json",
                success: function (rs) {
                    $("#kid").val(rs.kid);
                    $("#keyword").val(rs.keyword);
                    $("#stimes").val(rs.stimes);
                    var hm = new Date(parseFloat(rs.ltimes.substr(6)));
                    $("#ltimes").val(hm.toLocaleDateString());
                    if (rs.show) {
                        $("#show").get(0).selectedIndex = 0;
                    } else {
                        $("#show").get(0).selectedIndex = 1;
                    }

                }
            });
        }

        function update() {
            var cm = {
                kid: $("#kid").val(),
                keyword: $("#keyword").val(),
                stimes: $("#stimes").val(),
                ltimes: $("#ltimes").val(),
                show: $("#show").val()
            };
            $.ajax({
                type: "post",
                url: "@Url.Action("UpdateCMS_Keyword")",
                data: JSON.stringify({ kd: cm }),
                datatype: "json",
                contentType: "application/json",
                success: function (rs) {
                    if (rs>0) {
                        alert("修改成功！");
                        window.location = "@Url.Action("GetCMS_Keyword")";
                    } else {
                        alert("修改失败！");
                    }

                }
            });
        }

        function fan() {
            window.location.href = "https://localhost:44347/HouTaiArea/Index/GetCMS_Keyword";
        }
    </script>
</body>
